package com.penghk.learn.learnhadoopinspringboot.listener;

import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DemoListener implements ApplicationListener {


    @Autowired
    FileSystem fileSystem;


    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        if (applicationEvent instanceof ContextRefreshedEvent) {
            try {
                fileSystem.copyFromLocalFile(new Path("/home/penghk/ideaworkspace/learnHadoop/learnhadoop/input/source.txt"),
                        new Path("/input/source3.txt"));
                fileSystem.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("run success!");
        }
    }
}
